
layui.use(['form','layer'],function(){
    var form = layui.form,
		layer = parent.layer === undefined ? layui.layer : parent.layer;
    	$ = layui.jquery;

	//登录按钮事件
	form.on("submit(login)", function(data){
        $.post({
            url:'/login',
            method :'POST',
            data:{
                username : data.field.username,
                password : data.field.password
            },
            success : function(res) {
                console.data
                if(res.meta.code === 200){
                    layer.msg("登录成功");
                    setTimeout(function(){
                        location.href = res.data;
                    },500)
                }else{
                    layer.msg(res.meta.msg);
                }
            }
        });
        return false;
	});

	$("#randImage").click(function () {
		this.src = "/getCaptcha?t=" + Math.random();
	});
});
